home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / comms / non-internet / samba / source / smb.h < prev    next >
C/C++ Source or Header  |  1996-06-26  |  35KB  |  1,005 lines

  1. /* 
  2.    Unix SMB/Netbios implementation.
  3.    Version 1.9.
  4.    SMB parameters and setup
  5.    Copyright (C) Andrew Tridgell 1992-1995
  6.    
  7.    This program is free software; you can redistribute it and/or modify
  8.    it under the terms of the GNU General Public License as published by
  9.    the Free Software Foundation; either version 2 of the License, or
  10.    (at your option) any later version.
  11.    
  12.    This program is distributed in the hope that it will be useful,
  13.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.    GNU General Public License for more details.
  16.    
  17.    You should have received a copy of the GNU General Public License
  18.    along with this program; if not, write to the Free Software
  19.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. #ifndef _SMB_H
  22. #define _SMB_H
  23.  
  24. #ifndef MAX_CONNECTIONS
  25. #define MAX_CONNECTIONS 127
  26. #endif
  27.  
  28. #ifndef MAX_OPEN_FILES
  29. #define MAX_OPEN_FILES 50
  30. #endif
  31.  
  32. #ifndef GUEST_ACCOUNT
  33. #define GUEST_ACCOUNT "nobody"
  34. #endif
  35.  
  36. #define BUFFER_SIZE (0xFFFF)
  37. #define SAFETY_MARGIN 1024
  38.  
  39. #ifndef EXTERN
  40. #    define EXTERN extern
  41. #endif
  42.  
  43. #define False (0)
  44. #define True (1)
  45. #define BOOLSTR(b) ((b) ? "Yes" : "No")
  46. #define BITSETB(ptr,bit) ((((char *)ptr)[0] & (1<<(bit)))!=0)
  47. #define BITSETW(ptr,bit) ((SVAL(ptr,0) & (1<<(bit)))!=0)
  48. #define PTR_DIFF(p1,p2) ((ptrdiff_t)(((char *)(p1)) - (char *)(p2)))
  49.  
  50. typedef int BOOL;
  51.  
  52. /*
  53.    Samba needs type definitions for int16, int32, uint16 and uint32.
  54.    
  55.    Normally these are signed and unsigned 16 and 32 bit integers, but
  56.    they actually only need to be at least 16 and 32 bits
  57.    respectively. Thus if your word size is 8 bytes just defining them
  58.    as signed and unsigned int will work.
  59. */
  60.  
  61. /* afs/stds.h defines int16 and int32 */
  62. #ifndef AFS_AUTH
  63. typedef short int16;
  64. typedef int int32;
  65. #endif
  66.  
  67. #ifndef uint16
  68. typedef unsigned short uint16;
  69. #endif
  70.  
  71. #ifndef uint32
  72. typedef unsigned int uint32;
  73. #endif
  74.  
  75. #define SIZEOFWORD 2
  76.  
  77. #ifndef DEF_CREATE_MASK
  78. #define DEF_CREATE_MASK (0755)
  79. #endif
  80.  
  81. #ifndef DEFAULT_PIPE_TIMEOUT
  82. #define DEFAULT_PIPE_TIMEOUT 10000000 /* Ten seconds */
  83. #endif
  84.  
  85. /* debugging code */
  86. #ifndef SYSLOG
  87. #define DEBUG(level,body) ((DEBUGLEVEL>=(level))?(Debug1 body):0)
  88. #else
  89. EXTERN int syslog_level;
  90.  
  91. #define DEBUG(level,body) ((DEBUGLEVEL>=(level))? \
  92.                            (syslog_level = (level), Debug1 body):0)
  93. #endif
  94.  
  95. #define DIR_STRUCT_SIZE 43
  96.  
  97. /* these define all the command types recognised by the server - there
  98. are lots of gaps so probably there are some rare commands that are not
  99. implemented */
  100.  
  101. #define pSETDIR '\377'
  102.  
  103. /* these define the attribute byte as seen by DOS */
  104. #define aRONLY (1L<<0)
  105. #define aHIDDEN (1L<<1)
  106. #define aSYSTEM (1L<<2)
  107. #define aVOLID (1L<<3)
  108. #define aDIR (1L<<4)
  109. #define aARCH (1L<<5)
  110.  
  111. /* deny modes */
  112. #define DENY_DOS 0
  113. #define DENY_ALL 1
  114. #define DENY_WRITE 2
  115. #define DENY_READ 3
  116. #define DENY_NONE 4
  117. #define DENY_FCB 7
  118.  
  119. /* share types */
  120. #define STYPE_DISKTREE    0    /* Disk drive */
  121. #define STYPE_PRINTQ    1    /* Spooler queue */
  122. #define STYPE_DEVICE    2    /* Serial device */
  123. #define STYPE_IPC    3    /* Interprocess communication (IPC) */
  124.  
  125. /* SMB X/Open error codes for the ERRdos error class */
  126. #define ERRbadfunc 1 /* Invalid function (or system call) */
  127. #define ERRbadfile 2 /* File not found (pathname error) */
  128. #define ERRbadpath 3 /* Directory not found */
  129. #define ERRnofids 4 /* Too many open files */
  130. #define ERRnoaccess 5 /* Access denied */
  131. #define ERRbadfid 6 /* Invalid fid */
  132. #define ERRnomem 8 /* Out of memory */
  133. #define ERRbadmem 9 /* Invalid memory block address */
  134. #define ERRbadenv 10 /* Invalid environment */
  135. #define ERRbadaccess 12 /* Invalid open mode */
  136. #define ERRbaddata 13 /* Invalid data (only from ioctl call) */
  137. #define ERRres 14 /* reserved */
  138. #define ERRbaddrive 15 /* Invalid drive */
  139. #define ERRremcd 16 /* Attempt to delete current directory */
  140. #define ERRdiffdevice 17 /* rename/move across different filesystems */
  141. #define ERRnofiles 18 /* no more files found in file search */
  142. #define ERRbadshare 32 /* Share mode on file conflict with open mode */
  143. #define ERRlock 33 /* Lock request conflicts with existing lock */
  144. #define ERRfilexists 80 /* File in operation already exists */
  145. #define ERRbadpipe 230 /* Named pipe invalid */
  146. #define ERRpipebusy 231 /* All instances of pipe are busy */
  147. #define ERRpipeclosing 232 /* named pipe close in progress */
  148. #define ERRnotconnected 233 /* No process on other end of named pipe */
  149. #define ERRmoredata 234 /* More data to be returned */
  150. #define ERROR_EAS_DIDNT_FIT 275 /* Extended attributes didn't fit */
  151. #define ERROR_EAS_NOT_SUPPORTED 282 /* Extended attributes not suppored */
  152. #define ERRunknownlevel 124
  153. #define ERRunknownipc 2142
  154.  
  155.  
  156. /* here's a special one from observing NT */
  157. #define ERRnoipc 66 /* don't support ipc */
  158.  
  159. /* Error codes for the ERRSRV class */
  160.  
  161. #define ERRerror 1 /* Non specific error code */
  162. #define ERRbadpw 2 /* Bad password */
  163. #define ERRbadtype 3 /* reserved */
  164. #define ERRaccess 4 /* No permissions to do the requested operation */
  165. #define ERRinvnid 5 /* tid invalid */
  166. #define ERRinvnetname 6 /* Invalid servername */
  167. #define ERRinvdevice 7 /* Invalid device */
  168. #define ERRqfull 49 /* Print queue full */
  169. #define ERRqtoobig 50 /* Queued item too big */
  170. #define ERRinvpfid 52 /* Invalid print file in smb_fid */
  171. #define ERRsmbcmd 64 /* Unrecognised command */
  172. #define ERRsrverror 65 /* smb server internal error */
  173. #define ERRfilespecs 67 /* fid and pathname invalid combination */
  174. #define ERRbadlink 68 /* reserved */
  175. #define ERRbadpermits 69 /* Access specified for a file is not valid */
  176. #define ERRbadpid 70 /* reserved */
  177. #define ERRsetattrmode 71 /* attribute mode invalid */
  178. #define ERRpaused 81 /* Message server paused */
  179. #define ERRmsgoff 82 /* Not receiving messages */
  180. #define ERRnoroom 83 /* No room for message */
  181. #define ERRrmuns 87 /* too many remote usernames */
  182. #define ERRtimeout 88 /* operation timed out */
  183. #define ERRnoresource  89 /* No resources currently available for request. */
  184. #define ERRtoomanyuids 90 /* too many userids */
  185. #define ERRbaduid 91 /* bad userid */
  186. #define ERRuseMPX 250 /* temporarily unable to use raw mode, use MPX mode */
  187. #define ERRuseSTD 251 /* temporarily unable to use raw mode, use standard mode */
  188. #define ERRcontMPX 252 /* resume MPX mode */
  189. #define ERRbadPW /* reserved */
  190. #define ERRnosupport 0xFFFF
  191. #define ERRunknownsmb 22 /* from NT 3.5 response */
  192.  
  193.  
  194. /* Error codes for the ERRHRD class */
  195.  
  196. #define ERRnowrite 19 /* read only media */
  197. #define ERRbadunit 20 /* Unknown device */
  198. #define ERRnotready 21 /* Drive not ready */
  199. #define ERRbadcmd 22 /* Unknown command */
  200. #define ERRdata 23 /* Data (CRC) error */
  201. #define ERRbadreq 24 /* Bad request structure length */
  202. #define ERRseek 25
  203. #define ERRbadmedia 26
  204. #define ERRbadsector 27
  205. #define ERRnopaper 28
  206. #define ERRwrite 29 /* write fault */
  207. #define ERRread 30 /* read fault */
  208. #define ERRgeneral 31 /* General hardware failure */
  209. #define ERRwrongdisk 34
  210. #define ERRFCBunavail 35
  211. #define ERRsharebufexc 36 /* share buffer exceeded */
  212. #define ERRdiskfull 39
  213.  
  214.  
  215. typedef char pstring[1024];
  216. typedef char fstring[128];
  217. typedef fstring string;
  218.  
  219. typedef struct
  220. {
  221.   int size;
  222.   int mode;
  223.   int uid;
  224.   int gid;
  225.   /* these times are normally kept in GMT */
  226.   time_t mtime;
  227.   time_t atime;
  228.   time_t ctime;
  229.   pstring name;
  230. } file_info;
  231.  
  232.  
  233. /* Structure used when SMBwritebmpx is active */
  234. typedef struct
  235.         {
  236.     int   wr_total_written; /* So we know when to discard this */
  237.     int32 wr_timeout;
  238.     int32 wr_errclass;
  239.     int32 wr_error; /* Cached errors */
  240.     BOOL  wr_mode; /* write through mode) */
  241.     BOOL  wr_discard; /* discard all further data */
  242.         } write_bmpx_struct;
  243.  
  244. typedef struct
  245. {
  246.   int cnum;
  247.   int fd;
  248.   int pos;
  249.   int size;
  250.   int mode;
  251.   char *mmap_ptr;
  252.   int mmap_size;
  253.   write_bmpx_struct *wbmpx_ptr;
  254.   time_t open_time;
  255.   BOOL open;
  256.   BOOL can_lock;
  257.   BOOL can_read;
  258.   BOOL can_write;
  259.   BOOL share_mode;
  260.   BOOL share_pending;
  261.   BOOL print_file;
  262.   char *name;
  263. } files_struct;
  264.  
  265.  
  266. struct uid_cache {
  267.   int entries;
  268.   int list[UID_CACHE_SIZE];
  269. };
  270.  
  271. typedef struct
  272. {
  273.   int service;
  274.   BOOL force_user;
  275.   int uid; /* uid of user who *opened* this connection */
  276.   int gid; /* gid of user who *opened* this connection */
  277.   struct uid_cache uid_cache;
  278.   void *dirptr;
  279.   BOOL open;
  280.   BOOL printer;
  281.   BOOL ipc;
  282.   BOOL read_only;
  283.   BOOL admin_user;
  284.   char *dirpath;
  285.   char *connectpath;
  286.   char *origpath;
  287.   char *user; /* name of user who *opened* this connection */
  288.   /* following groups stuff added by ih */
  289.   /* This groups info is valid for the user that *opened* the connection */
  290.   int ngroups;
  291.   gid_t *groups;
  292.   int *igroups; /* an integer version - some OSes are broken :-( */
  293.   time_t lastused;
  294.   BOOL used;
  295.   int num_files_open;
  296. } connection_struct;
  297.  
  298.  
  299. typedef struct
  300. {
  301.   int uid; /* uid of a validated user */
  302.   int gid; /* gid of a validated user */
  303.   fstring name; /* name of a validated user */
  304.   BOOL guest;
  305.   /* following groups stuff added by ih */
  306.   /* This groups info is needed for when we become_user() for this uid */
  307.   int user_ngroups;
  308.   gid_t *user_groups;
  309.   int *user_igroups; /* an integer version - some OSes are broken :-( */
  310. } user_struct;
  311.  
  312.  
  313. enum {LPQ_QUEUED,LPQ_PAUSED,LPQ_SPOOLING,LPQ_PRINTING};
  314.  
  315. typedef struct
  316. {
  317.   int job;
  318.   int size;
  319.   int status;
  320.   int priority;
  321.   time_t time;
  322.   char user[30];
  323.   char file[100];
  324. } print_queue_struct;
  325.  
  326. enum {LPSTAT_OK, LPSTAT_STOPPED, LPSTAT_ERROR};
  327.  
  328. typedef struct
  329. {
  330.   fstring message;
  331.   int status;
  332. }  print_status_struct;
  333.  
  334.  
  335. /* this is used for smbstatus */
  336. struct connect_record
  337. {
  338.   int magic;
  339.   int pid;
  340.   int cnum;
  341.   int uid;
  342.   int gid;
  343.   char name[24];
  344.   char addr[24];
  345.   char machine[128];
  346.   time_t start;
  347. };
  348.  
  349.  
  350. #define LOCKING_VERSION 2
  351.  
  352. /* these are useful macros for checking validity of handles */
  353. #define VALID_FNUM(fnum)   (((fnum) >= 0) && ((fnum) < MAX_OPEN_FILES))
  354. #define OPEN_FNUM(fnum)    (VALID_FNUM(fnum) && Files[fnum].open)
  355. #define VALID_CNUM(cnum)   (((cnum) >= 0) && ((cnum) < MAX_CONNECTIONS))
  356. #define OPEN_CNUM(cnum)    (VALID_CNUM(cnum) && Connections[cnum].open)
  357. #define IS_IPC(cnum)       (VALID_CNUM(cnum) && Connections[cnum].ipc)
  358. #define FNUM_OK(fnum,c) (OPEN_FNUM(fnum) && (c)==Files[fnum].cnum)
  359.  
  360. #define CHECK_FNUM(fnum,c) if (!FNUM_OK(fnum,c)) \
  361.                                return(ERROR(ERRDOS,ERRbadfid))
  362. #define CHECK_READ(fnum) if (!Files[fnum].can_read) \
  363.                                return(ERROR(ERRDOS,ERRbadaccess))
  364. #define CHECK_WRITE(fnum) if (!Files[fnum].can_write) \
  365.                                return(ERROR(ERRDOS,ERRbadaccess))
  366. #define CHECK_ERROR(fnum) if (HAS_CACHED_ERROR(fnum)) \
  367.                                return(CACHED_ERROR(fnum))
  368.  
  369. /* translates a connection number into a service number */
  370. #define SNUM(cnum)         (Connections[cnum].service)
  371.  
  372. /* access various service details */
  373. #define SERVICE(snum)      (lp_servicename(snum))
  374. #define PRINTCAP           (lp_printcapname())
  375. #define PRINTCOMMAND(snum) (lp_printcommand(snum))
  376. #define PRINTERNAME(snum)  (lp_printername(snum))
  377. #define CAN_WRITE(cnum)    (OPEN_CNUM(cnum) && !Connections[cnum].read_only)
  378. #define VALID_SNUM(snum)   (lp_snum_ok(snum))
  379. #define GUEST_OK(snum)     (VALID_SNUM(snum) && lp_guest_ok(snum))
  380. #define GUEST_ONLY(snum)   (VALID_SNUM(snum) && lp_guest_only(snum))
  381. #define CAN_SETDIR(snum)   (!lp_no_set_dir(snum))
  382. #define CAN_PRINT(cnum)    (OPEN_CNUM(cnum) && lp_print_ok(SNUM(cnum)))
  383. #define POSTSCRIPT(cnum)   (OPEN_CNUM(cnum) && lp_postscript(SNUM(cnum)))
  384. #define MAP_HIDDEN(cnum)   (OPEN_CNUM(cnum) && lp_map_hidden(SNUM(cnum)))
  385. #define MAP_SYSTEM(cnum)   (OPEN_CNUM(cnum) && lp_map_system(SNUM(cnum)))
  386. #define MAP_ARCHIVE(cnum)   (OPEN_CNUM(cnum) && lp_map_archive(SNUM(cnum)))
  387. #define CREATE_MODE(cnum)  (lp_create_mode(SNUM(cnum)) | 0700)
  388. #ifdef SMB_PASSWD
  389. #define SMBENCRYPT()       (lp_encrypted_passwords())
  390. #else
  391. #define SMBENCRYPT() (False)
  392. #endif
  393.  
  394. /* the basic packet size, assuming no words or bytes */
  395. #define smb_size 39
  396.  
  397. /* offsets into message for common items */
  398. #define smb_com 8
  399. #define smb_rcls 9
  400. #define smb_reh 10
  401. #define smb_err 11
  402. #define smb_flg 13
  403. #define smb_flg2 14
  404. #define smb_reb 13
  405. #define smb_tid 28
  406. #define smb_pid 30
  407. #define smb_uid 32
  408. #define smb_mid 34
  409. #define smb_wct 36
  410. #define smb_vwv 37
  411. #define smb_vwv0 37
  412. #define smb_vwv1 39
  413. #define smb_vwv2 41
  414. #define smb_vwv3 43
  415. #define smb_vwv4 45
  416. #define smb_vwv5 47
  417. #define smb_vwv6 49
  418. #define smb_vwv7 51
  419. #define smb_vwv8 53
  420. #define smb_vwv9 55
  421. #define smb_vwv10 57
  422. #define smb_vwv11 59
  423. #define smb_vwv12 61
  424. #define smb_vwv13 63
  425. #define smb_vwv14 65
  426. #define smb_vwv15 67
  427. #define smb_vwv16 69
  428. #define smb_vwv17 71
  429.  
  430.  
  431. /* the complete */
  432. #define SMBmkdir      0x00   /* create directory */
  433. #define SMBrmdir      0x01   /* delete directory */
  434. #define SMBopen       0x02   /* open file */
  435. #define SMBcreate     0x03   /* create file */
  436. #define SMBclose      0x04   /* close file */
  437. #define SMBflush      0x05   /* flush file */
  438. #define SMBunlink     0x06   /* delete file */
  439. #define SMBmv         0x07   /* rename file */
  440. #define SMBgetatr     0x08   /* get file attributes */
  441. #define SMBsetatr     0x09   /* set file attributes */
  442. #define SMBread       0x0A   /* read from file */
  443. #define SMBwrite      0x0B   /* write to file */
  444. #define SMBlock       0x0C   /* lock byte range */
  445. #define SMBunlock     0x0D   /* unlock byte range */
  446. #define SMBctemp      0x0E   /* create temporary file */
  447. #define SMBmknew      0x0F   /* make new file */
  448. #define SMBchkpth     0x10   /* check directory path */
  449. #define SMBexit       0x11   /* process exit */
  450. #define SMBlseek      0x12   /* seek */
  451. #define SMBtcon       0x70   /* tree connect */
  452. #define SMBtconX      0x75   /* tree connect and X*/
  453. #define SMBtdis       0x71   /* tree disconnect */
  454. #define SMBnegprot    0x72   /* negotiate protocol */
  455. #define SMBdskattr    0x80   /* get disk attributes */
  456. #define SMBsearch     0x81   /* search directory */
  457. #define SMBsplopen    0xC0   /* open print spool file */
  458. #define SMBsplwr      0xC1   /* write to print spool file */
  459. #define SMBsplclose   0xC2   /* close print spool file */
  460. #define SMBsplretq    0xC3   /* return print queue */
  461. #define SMBsends      0xD0   /* send single block message */
  462. #define SMBsendb      0xD1   /* send broadcast message */
  463. #define SMBfwdname    0xD2   /* forward user name */
  464. #define SMBcancelf    0xD3   /* cancel forward */
  465. #define SMBgetmac     0xD4   /* get machine name */
  466. #define SMBsendstrt   0xD5   /* send start of multi-block message */
  467. #define SMBsendend    0xD6   /* send end of multi-block message */
  468. #define SMBsendtxt    0xD7   /* send text of multi-block message */
  469.  
  470. /* Core+ protocol */
  471. #define SMBlockread      0x13   /* Lock a range and read */
  472. #define SMBwriteunlock 0x14 /* Unlock a range then write */
  473. #define SMBreadbraw   0x1a  /* read a block of data with no smb header */
  474. #define SMBwritebraw  0x1d  /* write a block of data with no smb header */
  475. #define SMBwritec     0x20  /* secondary write request */
  476. #define SMBwriteclose 0x2c  /* write a file then close it */
  477.  
  478. /* dos extended protocol */
  479. #define SMBreadBraw      0x1A   /* read block raw */
  480. #define SMBreadBmpx      0x1B   /* read block multiplexed */
  481. #define SMBreadBs        0x1C   /* read block (secondary response) */
  482. #define SMBwriteBraw     0x1D   /* write block raw */
  483. #define SMBwriteBmpx     0x1E   /* write block multiplexed */
  484. #define SMBwriteBs       0x1F   /* write block (secondary request) */
  485. #define SMBwriteC        0x20   /* write complete response */
  486. #define SMBsetattrE      0x22   /* set file attributes expanded */
  487. #define SMBgetattrE      0x23   /* get file attributes expanded */
  488. #define SMBlockingX      0x24   /* lock/unlock byte ranges and X */
  489. #define SMBtrans         0x25   /* transaction - name, bytes in/out */
  490. #define SMBtranss        0x26   /* transaction (secondary request/response) */
  491. #define SMBioctl         0x27   /* IOCTL */
  492. #define SMBioctls        0x28   /* IOCTL  (secondary request/response) */
  493. #define SMBcopy          0x29   /* copy */
  494. #define SMBmove          0x2A   /* move */
  495. #define SMBecho          0x2B   /* echo */
  496. #define SMBopenX         0x2D   /* open and X */
  497. #define SMBreadX         0x2E   /* read and X */
  498. #define SMBwriteX        0x2F   /* write and X */
  499. #define SMBsesssetupX    0x73   /* Session Set Up & X (including User Logon) */
  500. #define SMBffirst        0x82   /* find first */
  501. #define SMBfunique       0x83   /* find unique */
  502. #define SMBfclose        0x84   /* find close */
  503. #define SMBinvalid       0xFE   /* invalid command */
  504.  
  505. /* Extended 2.0 protocol */
  506. #define SMBtrans2        0x32   /* TRANS2 protocol set */
  507. #define SMBtranss2       0x33   /* TRANS2 protocol set, secondary command */
  508. #define SMBfindclose     0x34   /* Terminate a TRANSACT2_FINDFIRST */
  509. #define SMBfindnclose    0x35   /* Terminate a TRANSACT2_FINDNOTIFYFIRST */
  510. #define SMBulogoffX      0x74   /* user logoff */
  511.  
  512.  
  513. /* these are the TRANS2 sub commands */
  514. #define TRANSACT2_OPEN          0
  515. #define TRANSACT2_FINDFIRST     1
  516. #define TRANSACT2_FINDNEXT      2
  517. #define TRANSACT2_QFSINFO       3
  518. #define TRANSACT2_SETFSINFO     4
  519. #define TRANSACT2_QPATHINFO     5
  520. #define TRANSACT2_SETPATHINFO   6
  521. #define TRANSACT2_QFILEINFO     7
  522. #define TRANSACT2_SETFILEINFO   8
  523. #define TRANSACT2_FSCTL         9
  524. #define TRANSACT2_IOCTL           10
  525. #define TRANSACT2_FINDNOTIFYFIRST 11
  526. #define TRANSACT2_FINDNOTIFYNEXT  12
  527. #define TRANSACT2_MKDIR           13
  528.  
  529.  
  530. /* these are the trans2 sub fields for primary requests */
  531. #define smb_tpscnt smb_vwv0
  532. #define smb_tdscnt smb_vwv1
  533. #define smb_mprcnt smb_vwv2
  534. #define smb_mdrcnt smb_vwv3
  535. #define smb_msrcnt smb_vwv4
  536. #define smb_flags smb_vwv5
  537. #define smb_timeout smb_vwv6
  538. #define smb_pscnt smb_vwv9
  539. #define smb_psoff smb_vwv10
  540. #define smb_dscnt smb_vwv11
  541. #define smb_dsoff smb_vwv12
  542. #define smb_suwcnt smb_vwv13
  543. #define smb_setup smb_vwv14
  544. #define smb_setup0 smb_setup
  545. #define smb_setup1 (smb_setup+2)
  546. #define smb_setup2 (smb_setup+4)
  547.  
  548. /* these are for the secondary requests */
  549. #define smb_spscnt smb_vwv2
  550. #define smb_spsoff smb_vwv3
  551. #define smb_spsdisp smb_vwv4
  552. #define smb_sdscnt smb_vwv5
  553. #define smb_sdsoff smb_vwv6
  554. #define smb_sdsdisp smb_vwv7
  555. #define smb_sfid smb_vwv8
  556.  
  557. /* and these for responses */
  558. #define smb_tprcnt smb_vwv0
  559. #define smb_tdrcnt smb_vwv1
  560. #define smb_prcnt smb_vwv3
  561. #define smb_proff smb_vwv4
  562. #define smb_prdisp smb_vwv5
  563. #define smb_drcnt smb_vwv6
  564. #define smb_droff smb_vwv7
  565. #define smb_drdisp smb_vwv8
  566.  
  567. /* where to find the base of the SMB packet proper */
  568. #define smb_base(buf) (((char *)(buf))+4)
  569.  
  570.  
  571. #define SUCCESS 0  /* The request was successful. */
  572. #define ERRDOS 0x01 /*  Error is from the core DOS operating system set. */
  573. #define ERRSRV 0x02  /* Error is generated by the server network file manager.*/
  574. #define ERRHRD 0x03  /* Error is an hardware error. */
  575. #define ERRCMD 0xFF  /* Command was not in the "SMB" format. */
  576.  
  577. /* structure used to hold the incoming hosts info */
  578. struct from_host {
  579.     char   *name;            /* host name */
  580.     char   *addr;            /* host address */
  581.     struct sockaddr_in *sin;        /* their side of the link */
  582. };
  583.  
  584. /* and a few prototypes */
  585. BOOL user_ok(char *user,int snum);
  586. int sys_rename(char *from, char *to);
  587. int sys_select(fd_set *fds,struct timeval *tval);
  588. int sys_unlink(char *fname);
  589. int sys_open(char *fname,int flags,int mode);
  590. DIR *sys_opendir(char *dname);
  591. int sys_stat(char *fname,struct stat *sbuf);
  592. int sys_lstat(char *fname,struct stat *sbuf);
  593. int sys_mkdir(char *dname,int mode);
  594. int sys_rmdir(char *dname);
  595. int sys_chdir(char *dname);
  596. int sys_utime(char *fname,struct utimbuf *times);
  597. int sys_disk_free(char *path,int *bsize,int *dfree,int *dsize);
  598. void lpq_reset(int);
  599. void status_printjob(int cnum,int snum,int jobid,int status);
  600. void DirCacheAdd(char *path,char *name,char *dname,int snum);
  601. char *DirCacheCheck(char *path,char *name,int snum);
  602. void DirCacheFlush(int snum);
  603. int interpret_character_set(char *str, int def);
  604. char *dos2unix_format(char *, BOOL);
  605. char *unix2dos_format(char *, BOOL);
  606. BOOL fcntl_lock(int fd,int op,uint32 offset,uint32 count,int type);
  607. void BlockSignals(BOOL block);
  608. void msleep(int t);
  609. int file_lock(char *name,int timeout);
  610. void file_unlock(int fd);
  611. int find_service(char *service);
  612. int TvalDiff(struct timeval *tvalold,struct timeval *tvalnew);
  613. int smb_offset(char *p,char *buf);
  614. void sync_file(int fnum);
  615. void PutUniCode(char *dst,char *src);
  616. void map_username(char *user);
  617. void close_low_fds(void);
  618. void clean_share_files(void);
  619. int write_socket(int fd,char *buf,int len);
  620. char *readdirname(void *p);
  621. int dos_chmod(int cnum,char *fname,int mode);
  622. int smb_numwords(char *buf);
  623. int get_share_mode(int cnum,struct stat *sbuf,int *pid);
  624. void del_share_mode(int fnum);
  625. BOOL set_share_mode(int fnum,int mode);
  626. int DSTDiff(time_t t);
  627. void TimeInit(void);
  628. void put_long_date(char *p,time_t t);
  629. time_t interpret_long_date(char *p);
  630. void dptr_idlecnum(int cnum);
  631. void dptr_closecnum(int cnum);
  632. void init_dptrs(void);
  633. void fault_setup();
  634. void set_socket_options(int fd, char *options);
  635. void putip(void *dest,void *src);
  636. void standard_sub_basic(char *s);
  637. void *OpenDir(char *name);
  638. void CloseDir(void *p);
  639. char *ReadDirName(void *p);
  640. BOOL SeekDir(void *p,int pos);
  641. int TellDir(void *p);
  642. int write_data(int fd,char *buffer,int N);
  643. BOOL server_cryptkey(char *buf);
  644. BOOL server_validate(char *buf);
  645. BOOL become_service(int cnum,BOOL do_chdir);
  646. BOOL snum_used(int snum);
  647. BOOL reload_services(BOOL test);
  648. void reopen_logs(void);
  649. int transfer_file(int infd,int outfd,int n,char *header,int headlen,int align);
  650. int str_checksum(char *s);
  651. time_t file_modtime(char *fname);
  652. BOOL do_match(char *str, char *regexp, int case_sig);
  653. BOOL is_a_socket(int fd);
  654. void _smb_setlen(char *buf,int len);
  655. void valid_initialise(void);
  656. BOOL is_8_3(char *fname);
  657. BOOL is_mangled(char *s);
  658. void standard_sub(int cnum,char *s);
  659. void del_printqueue(int cnum,int snum,int jobid);
  660. BOOL strisnormal(char *s);
  661. BOOL check_mangled_stack(char *s);
  662. int sys_chown(char *fname,int uid,int gid);
  663. int sys_chroot(char *dname);
  664. BOOL next_token(char **ptr,char *buff,char *sep);
  665. void invalidate_uid(int uid);
  666. char *fgets_slash(char *s,int maxlen,FILE *f);
  667. int read_udp_socket(int fd,char *buf,int len);
  668. void exit_server(char *reason);
  669. BOOL process_exists(int pid);
  670. BOOL chgpasswd(char *name,char *oldpass,char *newpass);
  671. void array_promote(char *array,int elsize,int element);
  672. void string_replace(char *s,char oldc,char newc);
  673. BOOL user_in_list(char *user,char *list);
  674. BOOL string_sub(char *s,char *pattern,char *insert);
  675. char *StrnCpy(char *dest,const char *src,int n);
  676. char *validated_username(int vuid);
  677. BOOL set_user_password(char *user,char *oldpass,char *newpass);
  678. int smb_buf_ofs(char *buf);
  679. char *skip_string(char *buf,int n);
  680. BOOL is_locked(int fnum,int cnum,uint32 count,uint32 offset);
  681. int read_file(int fnum,char *data,int pos,int mincnt,int maxcnt,int timeout,BOOL exact);
  682. BOOL do_lock(int fnum,int cnum,uint32 count,uint32 offset,int *eclass,uint32 *ecode);
  683. int seek_file(int fnum,int pos);
  684. BOOL do_unlock(int fnum,int cnum,uint32 count,uint32 offset,int *eclass,uint32 *ecode);
  685. int get_printqueue(int snum,int cnum,print_queue_struct **queue,print_status_struct *status);
  686. void parse_connect(char *buf,char *service,char *user,char *password,int *pwlen,char *dev);
  687. int setup_groups(char *user,int uid, int gid, int *p_ngroups, 
  688.          int **p_igroups, gid_t **p_groups);
  689. int make_connection(char *service,char *user,char *password, int pwlen, char *dev,int vuid);
  690. char *dptr_path(int key);
  691. char *dptr_wcard(int key);
  692. BOOL dptr_set_wcard(int key, char *wcard);
  693. BOOL dptr_set_attr(int key, uint16 attr);
  694. uint16 dptr_attr(int key);
  695. void dptr_close(int key);
  696. void dptr_closepath(char *path,int pid);
  697. int dptr_create(int cnum,char *path, BOOL expect_close,int pid);
  698. BOOL dptr_fill(char *buf,unsigned int key);
  699. BOOL dptr_zero(char *buf);
  700. void *dptr_fetch(char *buf,int *num);
  701. void *dptr_fetch_lanman2(char *params,int dptr_num);
  702. BOOL get_dir_entry(int cnum,char *mask,int dirtype,char *fname,int *size,int *mode,time_t *date,BOOL check_descend);
  703. void open_file(int fnum,int cnum,char *fname,int flags,int mode);
  704. void open_file_shared(int fnum,int cnum,char *fname,int share_mode,int ofun,int mode,int *Access,int *action);
  705. void close_file(int fnum);
  706. int reply_trans2(char *inbuf,char *outbuf,int length,int bufsize);
  707. int reply_trans(char *inbuf,char *outbuf);
  708. char *ufc_crypt(char *key,char *salt);
  709. BOOL authorise_login(int snum,char *user,char *password, int pwlen, 
  710.              BOOL *guest,BOOL *force,int vuid);
  711. void add_session_user(char *user);
  712. int valid_uid(int uid);
  713. user_struct *get_valid_user_struct(int uid);
  714. BOOL password_ok(char *user,char *password, int pwlen, struct passwd *pwd, BOOL nt_password);
  715. void register_uid(int uid,int gid,char *name,BOOL guest);
  716. BOOL fromhost(int sock,struct from_host *f);
  717. BOOL strhasupper(char *s);
  718. BOOL strhaslower(char *s);
  719. int disk_free(char *path,int *bsize,int *dfree,int *dsize);
  720. char *uidtoname(int uid);
  721. char *gidtoname(int gid);
  722. int get_share_mode_byname(int cnum,char *fname,int *pid);
  723. int get_share_mode_by_fnum(int cnum,int fnum,int *pid);
  724. BOOL check_file_sharing(int cnum,char *fname);
  725. char *StrCpy(char *dest,char *src);
  726. int unix_error_packet(char *inbuf,char *outbuf,int def_class,uint32 def_code,int line);
  727. time_t make_unix_date2(void *date_ptr);
  728. int cached_error_packet(char *inbuf,char *outbuf,int fnum,int line);
  729. mode_t unix_mode(int cnum,int dosmode);
  730. BOOL check_name(char *name,int cnum);
  731. int error_packet(char *inbuf,char *outbuf,int error_class,uint32 error_code,int line);
  732. int find_free_file(void );
  733. BOOL unix_convert(char *name,int cnum);
  734. void unix_convert_lanman2(char *s,char *home,BOOL case_is_sig);
  735. void print_file(int fnum);
  736. int read_smb_length(int fd,char *inbuf,int timeout);
  737. int read_predict(int fd,int offset,char *buf,char **ptr,int num);
  738. void invalidate_read_prediction(int fd);
  739. void do_read_prediction();
  740. BOOL claim_connection(int cnum,char *name,int max_connections,BOOL Clear);
  741. BOOL yield_connection(int cnum,char *name,int max_connections);
  742. int count_chars(char *s,char c);
  743. int smbrun(char *,char *);
  744. BOOL name_map_mangle(char *OutName,BOOL need83,int snum);
  745. struct hostent *Get_Hostbyname(char *name);
  746. struct passwd *Get_Pwnam(char *user,BOOL allow_change);
  747. void Abort(void);
  748. void *Realloc(void *p,int size);
  749. void smb_setlen(char *buf,int len);
  750. int set_message(char *buf,int num_words,int num_bytes,BOOL zero);
  751. BOOL check_access(int snum);
  752. BOOL in_group(gid_t group, int current_gid, int ngroups, int *groups);
  753. BOOL string_set(char **dest,char *src);
  754. BOOL string_init(char **dest,char *src);
  755. void string_free(char **s);
  756. char *attrib_string(int mode);
  757. void unix_format(char *fname);
  758. BOOL directory_exist(char *dname,struct stat *st);
  759. time_t make_unix_date3(void *date_ptr);
  760. void put_dos_date3(char *buf,int offset,time_t unixdate);
  761. void make_dir_struct(char *buf,char *mask,char *fname,unsigned int size,int mode,time_t date);
  762. BOOL in_list(char *s,char *list,BOOL case_sensitive);
  763. void strupper(char *s);
  764. BOOL file_exist(char *fname,struct stat *sbuf);
  765. int read_with_timeout(int fd,char *buf,int mincnt,int maxcnt, long time_out, BOOL exact);
  766. void close_sockets(void );
  767. BOOL send_smb(int fd,char *buffer);
  768. BOOL send_keepalive(int client);
  769. int read_data(int fd,char *buffer,int N);
  770. int smb_len(char *buf);
  771. BOOL receive_smb(int fd,char *buffer,int timeout);
  772. void show_msg(char *buf);
  773. BOOL big_endian(void );
  774. BOOL become_user(int cnum, int uid);
  775. BOOL unbecome_user(void);
  776. void become_daemon(void);
  777. BOOL reduce_name(char *s,char *dir,BOOL widelinks);
  778. void strlower(char *s);
  779. void strnorm(char *s);
  780. char *smb_buf(char *buf);
  781. char *smb_trans2_param(char *buf);
  782. char *smb_trans2_data(char *buf);
  783. BOOL strequal(char *,char *);
  784. BOOL strnequal(char *,char *,int n);
  785. BOOL strcsequal(char *,char *);
  786. BOOL mask_match( char *str, char *regexp, int case_sig, BOOL trans2);
  787. int dos_mode(int ,char *,struct stat *);
  788. char *timestring();
  789. BOOL ip_equal(struct in_addr ip1,struct in_addr ip2);
  790. BOOL send_one_packet(char *buf,int len,struct in_addr ip,int port,int type);
  791. char *get_home_dir(char *);
  792. int set_filelen(int fd, long len);
  793. void put_dos_date(char *buf,int offset,time_t unixdate);
  794. void put_dos_date2(char *buf,int offset,time_t unixdate);
  795. int lp_keepalive(void);
  796. int name_len(char *s);
  797. void dos_clean_name(char *s);
  798. void unix_clean_name(char *s);
  799. time_t make_unix_date(void *date_ptr);
  800. BOOL lanman2_match( char *str, char *regexp, int case_sig, BOOL autoext);
  801. BOOL trim_string(char *s,char *front,char *back);
  802. int byte_checksum(char *buf,int len);
  803. BOOL yesno(char *p);
  804. uint32 file_size(char *file_name);
  805. void dos_format(char *fname);
  806. char *GetWd(char *s);
  807. int name_mangle(char *in,char *out,char name_type);
  808. int name_len(char *s);
  809. void create_mangled_stack(int size);
  810. int name_extract(char *buf,int ofs,char *name);
  811. void get_broadcast(struct in_addr *if_ipaddr, struct in_addr *if_bcast, struct in_addr *if_nmask);
  812. BOOL allow_access(char *deny_list,char *allow_list,struct from_host *client);
  813. #ifdef __STDC__
  814. int Debug1(char *, ...);
  815. #else
  816. int Debug1();
  817. #endif
  818. BOOL check_hosts_equiv(char *user);
  819. int chain_reply(int type,char *inbuf,char *inbuf2,char *outbuf,char *outbuf2,int size,int bufsize);
  820. void close_cnum(int cnum,int uid);
  821. char *smb_errstr(char *inbuf);
  822. void GetTimeOfDay(struct timeval *tval);
  823. struct tm *LocalTime(time_t *t,int);
  824. int TimeDiff(time_t t);
  825. BOOL set_filetime(char *fname,time_t mtime);
  826. char *dirname_dos(char *path,char *buf);
  827. BOOL get_myname(char *myname,struct in_addr *ip);
  828. void expand_mask(char *Mask, BOOL);
  829. BOOL sane_unix_date(time_t unixdate);
  830. time_t start_of_month(void);
  831. char *smb_fn_name(int cnum);
  832. void get_machine_info(void);
  833. int open_socket_in(int type, int port, int dlevel);
  834. int open_socket_out(int type,struct in_addr *addr, int port );
  835. struct in_addr *interpret_addr2(char *str);
  836. BOOL zero_ip(struct in_addr ip);
  837. int read_max_udp(int fd,char *buffer,int bufsize,int maxtime);
  838. int interpret_protocol(char *str,int def);
  839. int interpret_security(char *str,int def);
  840. int ChDir(char *path);
  841. int smb_buflen(char *buf);
  842. unsigned long interpret_addr(char *str);
  843. void mangle_name_83(char *s);
  844. BOOL lp_casesignames(void);
  845. void setup_logging(char *pname,BOOL interactive);
  846. #ifdef DFS_AUTH
  847. void dfs_unlogin(void);
  848. extern int dcelogin_atmost_once;
  849. #endif
  850. #if AJT
  851. void ajt_panic(void);
  852. #endif
  853. #ifdef NOSTRDUP
  854. char *strdup(char *s);
  855. #endif
  856. #ifdef REPLACE_STRLEN
  857. int Strlen(char *);
  858. #endif
  859. #ifdef REPLACE_STRSTR
  860. char *Strstr(char *s, char *p);
  861. #endif
  862.  
  863. #ifndef MIN
  864. #define MIN(a,b) ((a)<(b)?(a):(b))
  865. #endif
  866. #ifndef MAX
  867. #define MAX(a,b) ((a)>(b)?(a):(b))
  868. #endif
  869.  
  870. #ifndef ABS
  871. #define ABS(a) ((a)>0?(a):(-(a)))
  872. #endif
  873.  
  874. #ifndef SIGNAL_CAST
  875. #define SIGNAL_CAST
  876. #endif
  877.  
  878. #ifndef SELECT_CAST
  879. #define SELECT_CAST
  880. #endif
  881.  
  882.  
  883. /* Some POSIX definitions for those without */
  884.  
  885. #ifndef S_IFDIR
  886. #define S_IFDIR         0x4000
  887. #endif
  888. #ifndef S_ISDIR
  889. #define S_ISDIR(mode)   ((mode & 0xF000) == S_IFDIR)
  890. #endif
  891. #ifndef S_IRWXU
  892. #define S_IRWXU 00700           /* read, write, execute: owner */
  893. #endif
  894. #ifndef S_IRUSR
  895. #define S_IRUSR 00400           /* read permission: owner */
  896. #endif
  897. #ifndef S_IWUSR
  898. #define S_IWUSR 00200           /* write permission: owner */
  899. #endif
  900. #ifndef S_IXUSR
  901. #define S_IXUSR 00100           /* execute permission: owner */
  902. #endif
  903. #ifndef S_IRWXG
  904. #define S_IRWXG 00070           /* read, write, execute: group */
  905. #endif
  906. #ifndef S_IRGRP
  907. #define S_IRGRP 00040           /* read permission: group */
  908. #endif
  909. #ifndef S_IWGRP
  910. #define S_IWGRP 00020           /* write permission: group */
  911. #endif
  912. #ifndef S_IXGRP
  913. #define S_IXGRP 00010           /* execute permission: group */
  914. #endif
  915. #ifndef S_IRWXO
  916. #define S_IRWXO 00007           /* read, write, execute: other */
  917. #endif
  918. #ifndef S_IROTH
  919. #define S_IROTH 00004           /* read permission: other */
  920. #endif
  921. #ifndef S_IWOTH
  922. #define S_IWOTH 00002           /* write permission: other */
  923. #endif
  924. #ifndef S_IXOTH
  925. #define S_IXOTH 00001           /* execute permission: other */
  926. #endif
  927.  
  928.  
  929. /* these are used in NetServerEnum to choose what to receive */
  930. #define SV_TYPE_WORKSTATION         0x00000001
  931. #define SV_TYPE_SERVER              0x00000002
  932. #define SV_TYPE_SQLSERVER           0x00000004
  933. #define SV_TYPE_DOMAIN_CTRL         0x00000008
  934. #define SV_TYPE_DOMAIN_BAKCTRL      0x00000010
  935. #define SV_TYPE_TIME_SOURCE         0x00000020
  936. #define SV_TYPE_AFP                 0x00000040
  937. #define SV_TYPE_NOVELL              0x00000080
  938. #define SV_TYPE_DOMAIN_MEMBER       0x00000100
  939. #define SV_TYPE_PRINTQ_SERVER       0x00000200
  940. #define SV_TYPE_DIALIN_SERVER       0x00000400
  941. #define SV_TYPE_SERVER_UNIX         0x00000800
  942. #define SV_TYPE_NT                  0x00001000
  943. #define SV_TYPE_WFW                 0x00002000
  944. #define SV_TYPE_SERVER_MFPN         0x00004000
  945. #define SV_TYPE_SERVER_NT           0x00008000
  946. #define SV_TYPE_POTENTIAL_BROWSER   0x00010000
  947. #define SV_TYPE_BACKUP_BROWSER      0x00020000
  948. #define SV_TYPE_MASTER_BROWSER      0x00040000
  949. #define SV_TYPE_DOMAIN_MASTER       0x00080000
  950. #define SV_TYPE_SERVER_OSF          0x00100000
  951. #define SV_TYPE_SERVER_VMS          0x00200000
  952. #define SV_TYPE_ALTERNATE_XPORT     0x20000000  
  953. #define SV_TYPE_LOCAL_LIST_ONLY     0x40000000  
  954. #define SV_TYPE_DOMAIN_ENUM         0x80000000
  955. #define SV_TYPE_ALL                 0xFFFFFFFF  
  956.  
  957.  
  958.  
  959. /* protocol types. It assumes that higher protocols include lower protocols
  960.    as subsets */
  961. enum protocol_types {PROTOCOL_NONE,PROTOCOL_CORE,PROTOCOL_COREPLUS,PROTOCOL_LANMAN1,PROTOCOL_LANMAN2,PROTOCOL_NT1};
  962.  
  963. /* security levels */
  964. enum security_types {SEC_SHARE,SEC_USER,SEC_SERVER};
  965.  
  966. /* printing types */
  967. enum printing_types {PRINT_BSD,PRINT_SYSV,PRINT_AIX,PRINT_HPUX,PRINT_QNX};
  968.  
  969.  
  970. /* case handling */
  971. enum case_handling {CASE_LOWER,CASE_UPPER};
  972.  
  973.  
  974. /* Macros to get at offsets within smb_lkrng and smb_unlkrng
  975.    structures. We cannot define these as actual structures
  976.    due to possible differences in structure packing
  977.    on different machines/compilers. */
  978.  
  979. #define SMB_LPID_OFFSET(indx) (10 * (indx))
  980. #define SMB_LKOFF_OFFSET(indx) ( 2 + (10 * (indx)))
  981. #define SMB_LKLEN_OFFSET(indx) ( 6 + (10 * (indx)))
  982.  
  983. /* Macro to cache an error in a write_bmpx_struct */
  984. #define CACHE_ERROR(w,c,e) ((w)->wr_errclass = (c), (w)->wr_error = (e), \
  985.                 w->wr_discard = True, -1)
  986. /* Macro to test if an error has been cached for this fnum */
  987. #define HAS_CACHED_ERROR(fnum) (Files[(fnum)].open && \
  988.                 Files[(fnum)].wbmpx_ptr && \
  989.                 Files[(fnum)].wbmpx_ptr->wr_discard)
  990. /* Macro to turn the cached error into an error packet */
  991. #define CACHED_ERROR(fnum) cached_error_packet(inbuf,outbuf,fnum,__LINE__)
  992.  
  993. /* these are the datagram types */
  994. #define DGRAM_DIRECT_UNIQUE 0x10
  995.  
  996. #define ERROR(class,x) error_packet(inbuf,outbuf,class,x,__LINE__)
  997.  
  998. /* this is how errors are generated */
  999. #define UNIXERROR(defclass,deferror) unix_error_packet(inbuf,outbuf,defclass,deferror,__LINE__)
  1000.  
  1001. #define ROUNDUP(x,g) (((x)+((g)-1))&~((g)-1))
  1002.  
  1003. #endif 
  1004. /* _SMB_H */
  1005.